//
//  GJFMerchantDetailTagTableViewCell.m
//  Wedding
//
//  Created by 郭静芬 on 2017/1/3.
//  Copyright © 2017年 郭静芬. All rights reserved.
//

#import "GJFMerchantDetailTagTableViewCell.h"

@interface GJFMerchantDetailTagTableViewCell ()
@property (nonatomic, strong) UILabel *tagName;
@property (nonatomic, strong) UILabel *tag1;
@property (nonatomic, strong) UILabel *tag2;
@property (nonatomic, strong) UILabel *tag3;
@property (nonatomic, strong) UILabel *tag4;
@property (nonatomic, strong) UILabel *tag5;
@property (nonatomic, strong) UILabel *tag6;
@end

@implementation GJFMerchantDetailTagTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setMerchantModel:(GJFMerchantModel *)merchantModel {
    _merchantModel = merchantModel;
    
    self.tag1.hidden = NO;
    self.tag2.hidden = NO;
    self.tag3.hidden = NO;
    self.tag4.hidden = NO;
    self.tag5.hidden = NO;
    self.tag6.hidden = NO;
    NSArray *tagArr = [merchantModel.taglist componentsSeparatedByString:@","];
    //根据标签所有的个数作隐藏
    if (!tagArr || tagArr.count == 0 || [merchantModel.taglist length] == 0) {
        self.tag1.hidden = YES;
        self.tag2.hidden = YES;
        self.tag3.hidden = YES;
        self.tag4.hidden = YES;
        self.tag5.hidden = YES;
        self.tag6.hidden = YES;
        
    } else {
        if (tagArr[0]) {
            self.tag1.text = tagArr[0];
        }
        else {
            self.tag1.hidden = YES;
        }
        if (tagArr.count > 1) {
            self.tag2.text = tagArr[1];
        }
        else {
            self.tag2.hidden = YES;
        }
        if (tagArr.count > 2) {
            self.tag3.text = tagArr[2];
        }
        else {
            self.tag3.hidden = YES;
        }
        if (tagArr.count > 3) {
            self.tag4.text = tagArr[3];
        }
        else {
            self.tag4.hidden = YES;
        }
        if (tagArr.count > 4) {
            self.tag5.text = tagArr[4];
        }
        else {
            self.tag5.hidden = YES;
        }
        if (tagArr.count > 5) {
            self.tag6.text = tagArr[5];
        }
        else {
            self.tag6.hidden = YES;
        }
    }

}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.tagName.frame = CGRectMake(10 * XX, 25 * YY, WIDTH - 20 * XX, 25 * YY);
    self.tag1.frame = CGRectMake(25 * XX, self.tagName.frame.size.height + 40 * YY, 70 * XX, 20 * YY);
    self.tag2.frame = CGRectMake(110 * XX, self.tag1.frame.origin.y, 70 * XX, 20 * YY);
    self.tag3.frame = CGRectMake(195 * XX, self.tag1.frame.origin.y, 70 * XX, 20 * YY);
    self.tag4.frame = CGRectMake(280 * XX, self.tag1.frame.origin.y, 70 * XX, 20 * YY);
    self.tag5.frame = CGRectMake(110 * XX, self.tag1.frame.size.height + self.tag1.frame.origin.y + 10, 70 * XX, 20 * YY);
    self.tag6.frame = CGRectMake(195 * XX, self.tag5.frame.origin.y, 70 * XX, 20 * YY);

}

- (UILabel *)tagName {
    if (!_tagName) {
        _tagName = [[UILabel alloc] init];
        _tagName.text = @"标签";
        _tagName.textColor = HOMECOLOR;
        _tagName.font = [UIFont systemFontOfSize:19 * XX];
        _tagName.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_tagName];
    }
    return _tagName;
}
- (UILabel *)tag1 {
    if (!_tag1) {
        _tag1 = [[UILabel alloc] init];
        _tag1.font = [UIFont systemFontOfSize:11 * XX];
        _tag1.textColor = [UIColor redColor];
        _tag1.layer.borderColor = [UIColor redColor].CGColor;
        _tag1.layer.borderWidth = 1;
        _tag1.textAlignment = NSTextAlignmentCenter;
        _tag1.layer.cornerRadius = 10 * YY;
        _tag1.clipsToBounds = YES;
        [self.contentView addSubview:_tag1];
    }
    return _tag1;
}
- (UILabel *)tag2 {
    if (!_tag2) {
        _tag2 = [[UILabel alloc] init];
        _tag2.font = [UIFont systemFontOfSize:11 * XX];
        _tag2.textColor = [UIColor purpleColor];
        _tag2.layer.borderColor = [UIColor purpleColor].CGColor;
        _tag2.layer.borderWidth = 1;
        _tag2.textAlignment = NSTextAlignmentCenter;
        _tag2.layer.cornerRadius = 10 * YY;
        _tag2.clipsToBounds = YES;
        [self.contentView addSubview:_tag2];
    }
    return _tag2;
}
- (UILabel *)tag3 {
    if (!_tag3) {
        _tag3 = [[UILabel alloc] init];
        _tag3.font = [UIFont systemFontOfSize:11 * XX];
        _tag3.textColor = [UIColor orangeColor];
        _tag3.layer.borderColor = [UIColor orangeColor].CGColor;
        _tag3.layer.borderWidth = 1;
        _tag3.textAlignment = NSTextAlignmentCenter;
        _tag3.layer.cornerRadius = 10 * YY;
        _tag3.clipsToBounds = YES;
        [self.contentView addSubview:_tag3];
    }
    return _tag3;
}
- (UILabel *)tag4 {
    if (!_tag4) {
        _tag4 = [[UILabel alloc] init];
        _tag4.font = [UIFont systemFontOfSize:11 * XX];
        _tag4.textColor = [UIColor cyanColor];
        _tag4.layer.borderColor = [UIColor cyanColor].CGColor;
        _tag4.layer.borderWidth = 1;
        _tag4.textAlignment = NSTextAlignmentCenter;
        _tag4.layer.cornerRadius = 10 * YY;
        _tag4.clipsToBounds = YES;
        [self.contentView addSubview:_tag4];
    }
    return _tag4;
}
- (UILabel *)tag5 {
    if (!_tag5) {
        _tag5 = [[UILabel alloc] init];
        _tag5.font = [UIFont systemFontOfSize:11 * XX];
        _tag5.textColor = [UIColor greenColor];
        _tag5.layer.borderColor = [UIColor greenColor].CGColor;
        _tag5.layer.borderWidth = 1;
        _tag5.textAlignment = NSTextAlignmentCenter;
        _tag5.layer.cornerRadius = 10 * YY;
        _tag5.clipsToBounds = YES;
        [self.contentView addSubview:_tag5];
    }
    return _tag5;
}
- (UILabel *)tag6 {
    if (!_tag6) {
        _tag6 = [[UILabel alloc] init];
        _tag6.font = [UIFont systemFontOfSize:11 * XX];
        _tag6.textColor = [UIColor blueColor];
        _tag6.layer.borderColor = [UIColor blueColor].CGColor;
        _tag6.layer.borderWidth = 1;
        _tag6.textAlignment = NSTextAlignmentCenter;
        _tag6.layer.cornerRadius = 10 * YY;
        _tag6.clipsToBounds = YES;
        [self.contentView addSubview:_tag6];
    }
    return _tag6;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
